package com.whcoding.jpa.dao;

import com.whcoding.jpa.pojo.OrmDeptPO;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Repository
public interface DeptDao extends JpaRepository<OrmDeptPO, Integer> {

	/**
	 * JPA 增加事务处理
	 *
	 * @param type
	 */
	@Transactional(rollbackFor = Exception.class)
	@Modifying
	@Query(value = "DELETE FROM orm_dept where dept_id = ?1 and is_valid_flag = 1", nativeQuery = true)
	void deleteOrmDeptVOByDeptId(Long type);

	/**
	 * 自定义SQL查询
	 * @param deptName
	 * @return
	 */
	@Query(value = "select * from orm_dept where dept_name=(:deptName)", nativeQuery = true)
	List<OrmDeptPO> queryDeptByName(@Param("deptName") String deptName);

	/**
	 * 根据DeptName 查询数据
	 *
	 * @param deptName
	 * @return
	 */
	OrmDeptPO findByDeptName(String deptName);



}
